<?php
final class GuestBookPresetMessageModel {
	private $mysql;
	private $tableName = 'GuestBookPresetMessage';
	public $idRowName = 'GuestBookPresetMessage_ID';
	public $textRowName = 'GuestBookPresetMessage_text';
	public $langCodeRowName = 'Language_Code';
	public $CountRowName = 'GuestBookPresetMessage_Count';

	public function __construct ($mysql) {
		$this->mysql = $mysql;
	}

	public function GetGuestBookPresetMessageCount ($lang = NULL) {
		$ref = 0;
		$sql = '';
		if ($lang == NULL) {
			$sql = sprintf ('SELECT COUNT(*) AS `%s` FROM `%s`;', $this->mysql->escape_string ($this->CountRowName), $this->mysql->escape_string ($this->tableName));
		} else {
			$sql = sprintf ('SELECT COUNT(*) AS `%s` FROM `%s` WHERE `%s`=\'%s\';', $this->mysql->escape_string ($this->CountRowName), $this->mysql->escape_string ($this->tableName), $this->mysql->escape_string ($this->langCodeRowName), $this->mysql->escape_string ($lang));
		}
		$sqlresult = $this->mysql->query ($sql);
		$len = $sqlresult->num_rows ();
		if ($len > 0) {
			$data = $sqlresult->fetch_array ();
			$ref = $data[$this->CountRowName];
		}
		$sqlresult->free_result ();
		return $ref;
	}
///////
	public function CheckGuestBookPresetMessageItemExist ($ID) {
		$ref = NULL;
		$sqlresult = $this->mysql->query (sprintf ('SELECT `%s`, `%s`, `%s` FROM `%s` WHERE `%s`=%d;', $this->mysql->escape_string ($this->idRowName), $this->mysql->escape_string ($this->textRowName), $this->mysql->escape_string ($this->langCodeRowName), $this->mysql->escape_string ($this->tableName), $this->mysql->escape_string ($this->idRowName), $this->mysql->escape_string ($ID)));
		$len = $sqlresult->affected_rows ();
		if ($len > 0) {
			$ref = $sqlresult->fetch_array ();
		}
		$sqlresult->free_result ();
		return $ref;
	}
#	public function GetGuestBookPresetMessageItems ($offset, $count, $lang = NULL) {
#		$ref = array ();
#		$sql = '';
#		if ($lang == NULL) {
#			$sql = sprintf ('SELECT `%s`, `%s`, `%s` FROM `%s` LIMIT %d, %d;', $this->mysql->escape_string ($this->idRowName), $this->mysql->escape_string ($this->textRowName), $this->mysql->escape_string ($this->langCodeRowName), $this->mysql->escape_string ($this->tableName), $this->mysql->escape_string ($offset), $this->mysql->escape_string ($count));
#		} else {
#			$sql = sprintf ('SELECT `%s`, `%s`, `%s` FROM `%s` WHERE `%s`=\'%s\' LIMIT %d, %d;', $this->mysql->escape_string ($this->idRowName), $this->mysql->escape_string ($this->textRowName), $this->mysql->escape_string ($this->langCodeRowName), $this->mysql->escape_string ($this->tableName), $this->mysql->escape_string ($this->langCodeRowName), $this->mysql->escape_string ($lang), $this->mysql->escape_string ($offset), $this->mysql->escape_string ($count));
#		}
#		$sqlresult = $this->mysql->query ($sql);
#		while ($data = $sqlresult->fetch_array ()) {
#			$ref[] = $data;
#		}
#		$sqlresult->free_result ();
#		return $ref;
#	}
///////

	public function GetGuestBookPresetMessageItems ($offset, $count, $lang = NULL) {
		$ref = array ();
		$sql = '';
		if ($lang == NULL) {
			$sql = sprintf ('SELECT `%s`, `%s`, `%s` FROM `%s` LIMIT %d, %d;', $this->mysql->escape_string ($this->idRowName), $this->mysql->escape_string ($this->textRowName), $this->mysql->escape_string ($this->langCodeRowName), $this->mysql->escape_string ($this->tableName), $this->mysql->escape_string ($offset), $this->mysql->escape_string ($count));
		} else {
			$sql = sprintf ('SELECT `%s`, `%s`, `%s` FROM `%s` WHERE `%s`=\'%s\' LIMIT %d, %d;', $this->mysql->escape_string ($this->idRowName), $this->mysql->escape_string ($this->textRowName), $this->mysql->escape_string ($this->langCodeRowName), $this->mysql->escape_string ($this->tableName), $this->mysql->escape_string ($this->langCodeRowName), $this->mysql->escape_string ($lang), $this->mysql->escape_string ($offset), $this->mysql->escape_string ($count));
		}
		$sqlresult = $this->mysql->query ($sql);
		while ($data = $sqlresult->fetch_array ()) {
			$ref[] = $data;
		}
		$sqlresult->free_result ();
		return $ref;
	}

	public function DelGuestBookPresetMessageItem ($id) {
		$len = 0;
		$sqlresult = $this->mysql->query (sprintf ('DELETE FROM `%s` WHERE `%s`=\'%s\';', $this->mysql->escape_string ($this->tableName), $this->mysql->escape_string ($this->idRowName), $this->mysql->escape_string ($id)));
		$len = $sqlresult->affected_rows ();
		$sqlresult->free_result ();
		return $len;
	}

	public function AddGuestBookPresetMessageItem ($description, $lang) {
		$sqlresult = $this->mysql->query (sprintf ('INSERT INTO `%s` (`%s`, `%s`) VALUES (\'%s\', \'%s\');', $this->mysql->escape_string ($this->tableName), $this->mysql->escape_string ($this->textRowName), $this->mysql->escape_string ($this->langCodeRowName), $this->mysql->escape_string ($description), $this->mysql->escape_string ($lang)));
		$sqlresult->free_result ();
	}

	public function EditGuestBookPresetMessageItem ($description, $lang, $id) {
		$sqlresult = $this->mysql->query (sprintf ('UPDATE `%s` SET `%s`=\'%s\', `%s`=\'%s\' WHERE `%s`=%d;', $this->mysql->escape_string ($this->tableName), $this->mysql->escape_string ($this->textRowName), $this->mysql->escape_string ($description), $this->mysql->escape_string ($this->langCodeRowName), $this->mysql->escape_string ($lang), $this->mysql->escape_string ($this->idRowName), $this->mysql->escape_string ($id)));
		$sqlresult->free_result ();
	}

}
?>
